#include "stdio.h"
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FIFO "./fifo"

int main() {
    int fd = open(FIFO, O_WRONLY);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    
    char buf[128];

    while (1) {
        printf("please enter# ");
        fflush(stdout);
        buf[0] = 0;
        ssize_t s = read(0, buf, sizeof(buf)-1);
        if (s > 0) {
            buf[s] = 0;
            write(fd, buf, strlen(buf));    
        }else if(s == 0) {
            break;
        }else {
            break;
        }
    }
    close(fd);
    return 0; 
}
